package net.lab1024.sa.admin.module.flowable.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import jakarta.annotation.Resource;
import net.lab1024.sa.admin.module.flowable.annotation.EnterpriseAndApplicationCodeProperty;
import net.lab1024.sa.admin.module.flowable.domain.AjaxResult;
import net.lab1024.sa.admin.module.flowable.domain.FlowableFieldDef;
import net.lab1024.sa.admin.module.flowable.page.TableDataInfo;
import net.lab1024.sa.admin.module.flowable.service.IFlowableFieldDefService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 流程字段定义Controller
 *
 * @author ruoyi
 * @date 2023-12-26
 */
@RestController
@RequestMapping("/flowable/def")
public class FlowableFieldDefController extends BaseController
{
    @Resource
    private IFlowableFieldDefService flowableFieldDefService;

    /**
     * 查询流程字段定义列表
     */
    @SaCheckPermission("flowable:def:list")
    @GetMapping("/list")
    public TableDataInfo list(FlowableFieldDef flowableFieldDef)
    {
        startPage();
        List<FlowableFieldDef> list = flowableFieldDefService.selectFlowableFieldDefList(flowableFieldDef);
        return getDataTable(list);
    }

    /**
     * 导出流程字段定义列表
     */
/*
    @SaCheckPermission("flowable:def:export")
    @Log(title = "流程字段定义", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, FlowableFieldDef flowableFieldDef)
    {
        List<FlowableFieldDef> list = flowableFieldDefService.selectFlowableFieldDefList(flowableFieldDef);
        ExcelUtil<FlowableFieldDef> util = new ExcelUtil<FlowableFieldDef>(FlowableFieldDef.class);
        util.exportExcel(response, list, "流程字段定义数据");
    }
*/

    /**
     * 获取流程字段定义详细信息
     */
    @SaCheckPermission("flowable:def:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(flowableFieldDefService.selectFlowableFieldDefById(id));
    }

    /**
     * 新增流程字段定义
     */
    @SaCheckPermission("flowable:def:add")
    @PostMapping
    public AjaxResult add(@RequestBody FlowableFieldDef flowableFieldDef)
    {
        return toAjax(flowableFieldDefService.insertFlowableFieldDef(flowableFieldDef));
    }

    /**
     * 修改流程字段定义
     */
    @SaCheckPermission("flowable:def:edit")
    @PutMapping
    public AjaxResult edit(@RequestBody FlowableFieldDef flowableFieldDef)
    {
        return toAjax(flowableFieldDefService.updateFlowableFieldDef(flowableFieldDef));
    }

    /**
     * 删除流程字段定义
     */
    @SaCheckPermission("flowable:def:remove")
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(flowableFieldDefService.deleteFlowableFieldDefByIds(ids));
    }
    /**
     * 查询流程字段定义列表(不翻页)
     */
    @SaCheckPermission("flowable:def:listAll")
    @GetMapping("/listAll")
    public AjaxResult listAll(FlowableFieldDef flowableFieldDef)
    {
        List<FlowableFieldDef> list = flowableFieldDefService.selectFlowableFieldDefList(flowableFieldDef);
        return success(list);
    }

}
